package top.colordreams.tenant.resolver;

/**
 * 缓存当前租户ID解析器委托
 *
 * @author 秋辞未寒
 */
public class CacheCurrentTenantResolverDelegate implements CurrentTenantResolver {

    private final CurrentTenantResolver delegate;

    private String currentTenantId;

    public CacheCurrentTenantResolverDelegate(CurrentTenantResolver delegate) {
        this.delegate = delegate;
    }

    @Override
    public synchronized String resolveCurrentTenantId() {
        if (currentTenantId == null) {
            currentTenantId = delegate.resolveCurrentTenantId();
        }
        return currentTenantId;
    }

}
